import React = require("react");
import { PageProps } from "maishu-chitu-react";
import { DesignView } from "controls/design-view";
import { pageDatas } from "services/page-datas";
import { LocalService } from "services/local-service";
import { PageSpiner, PageSpinerContext } from "controls/page-spiner";

type LoadResult = ReturnType<StoreMenuPage["loadData"]> extends Promise<infer T> ? T : any;
export default class StoreMenuPage extends React.Component<PageProps> {
    localService: LocalService;
    constructor(props) {
        super(props);

        this.localService = this.props.createService(LocalService);
    }

    async loadData() {
        let record = await pageDatas.shoppingCart();
        console.assert(record != null);
        return { record };
    }

    render() {
        return <PageSpiner load={() => this.loadData()}>
            <PageSpinerContext.Consumer>
                {args => {
                    let result: LoadResult = args.result;
                    return <DesignView {...this.props} pageDataRecord={result.record}></DesignView>
                }}
            </PageSpinerContext.Consumer>
        </PageSpiner>
    }
}